package cn.edu.scau.cmi.zenglinghong.client;

import cn.edu.scau.cmi.zenglinghong.factory.*;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class FactoryClient extends Application{

	public static void main(String[] args) {
		launch(args);
	}
	
	@Override
	public void start(Stage primaryStage) throws Exception {
		// TODO Auto-generated method stub
		init(primaryStage);
	}

	public static void init(Stage primaryStage) throws Exception {
		// TODO Auto-generated method stub
		Label label = new Label("请输入需要的肉类(pork,beef,chicken):");
		TextField textField = new TextField();
		Button button = new Button("确认");
		TextArea textArea = new TextArea();
		textArea.setEditable(false);
		
		VBox root = new VBox();
		root.setSpacing(20);
		Scene scene = new Scene(root,400,300);
		primaryStage.setScene(scene);
		
		root.getChildren().add(label);
		root.getChildren().add(textField);
		root.getChildren().add(button);
		root.getChildren().add(textArea);
		
		button.setOnAction(sigHandle -> {
			MeatFactory meatFactory = null;
			switch (textField.getText()) {
			case "beef":
				meatFactory = new BeefFactory(); break;
			case "chicken":
				meatFactory = new ChickenFactory(); break;
			case "pork":
				meatFactory = new PorkFactory(); break;
			default:
				textArea.setText("There is no such meat.");
			}
			if(meatFactory != null) {
				//Meat meat = meatFactory.getMeat();
				//meat.cook();
				textArea.setText(textField.getText()+" is delicious.");
			}
		});
		
		primaryStage.setTitle("工厂模式");
		primaryStage.show();
	}

//	public static void main(String[] args) {
//		Scanner in = new Scanner(System.in);
//		System.out.println("请输入需要的肉类(pork,beef,chicken):");
//		String meatType = in.next();
//		in.close();
//		MeatFactory meatFactory = null;
//		switch (meatType) {
//		case "beef":
//			meatFactory = new BeefFactory(); break;
//		case "chicken":
//			meatFactory = new ChickenFactory(); break;
//		case "pork":
//			meatFactory = new PorkFactory(); break;
//		default:
//			System.out.println("There is no such meat.");
//		}
//		if(meatFactory != null) {
//			Meat meat = meatFactory.getMeat();
//			meat.cook();
//		}
//	}

}
